package com.example.API;

public class TestInteger {
    public static void main(String[] args) {
        Integer i1 = new Integer("100");
        Integer i2 = new Integer(100);
        System.out.println(i1); //100
        System.out.println(i2); //100

        Integer i3 = Integer.valueOf("200");
        Integer i4 = Integer.valueOf(200);
        System.out.println(i3); //200
        System.out.println(i4); //200

        Integer a1 = 100;      //自动装箱
        //对象     = 默认是一个基本数据类型
        System.out.println(a1);

        int a2 = a1;    //自动拆箱
        System.out.println(a2);

        Integer a3 = 100;   //自动装箱
        a3 += 200;          //a3 = a3 + 200;
        //会把a3这个对象变成基本数据类型100
        //100 + 200 = 300
        //把基本数据类型300再次自动装箱变成Integer对象赋给a3
        System.out.println(a3);

        //细节
        Integer a4 = null;
        if (a4 != null) {
            a4 += 200;
            System.out.println(a4);
        }

        String s1 = "100";
        int i5 = 200;
        System.out.println(s1 + i5);    //字符串 + 任意数据类型  结果都是一个字符串

        //String -> int
        int i6 = Integer.parseInt(s1);
        System.out.println(i6 + 200);    //300

        //int -> String
        //一：+""
        int n1 = 100;
        String s2 = n1 + "";
        System.out.println(s2 + 100);   //100100
        //二：调用String类中的valueOf方法
        String s3 = String.valueOf(n1);
        System.out.println(s3 + 100);   //100100
    }
}
